home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / addr / ap_t2parts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  2.9 KB  |  130 lines

  1. #include "util.h"
  2. #include "ap.h"
  3. #include "ll_log.h"
  4.  
  5. /*  Record beginnings of major sections of an address
  6.  *
  7.  *  Returns:    pointer to next node, after address
  8.  *               0 if end of tree
  9.  *              -1 if error
  10.  *
  11.  *  if both rroute and nroute are requested, and the tree has routing
  12.  *  in reverse-path form, then these will point to the same node.
  13.  */
  14.  
  15.  
  16. extern LLog *logptr;
  17.  
  18. LOCVAR    int perlev, grplev;
  19.  
  20. AP_ptr
  21.     ap_t2parts (tree, group, name, local, domain, route)
  22.     register AP_ptr  tree;      /* the parse tree */
  23.                 /* THESE ARE POINTERS TO POINTERS */
  24.                 /* where to stuff the relevant pointers */
  25.     AP_ptr  *group,             /* beginning of group name  */
  26.         *name,              /* beginning of person name  */
  27.         *local,             /* beginning of local-part */
  28.         *domain,            /* basic domain reference */
  29.         *route;             /* beginning of 822 reverse routing */
  30. {
  31.     AP_ptr retptr;
  32.     int gotlocal;
  33.  
  34. #ifdef DEBUG
  35.     ll_log (logptr, LLOGFTR, "ap_t2parts ()");
  36. #endif
  37.  
  38.     if (tree -> ap_obtype == APV_NIL)
  39.     return ((AP_ptr) OK);      /* Ignore null stuff */
  40.  
  41.     grplev = perlev = 0;
  42.  
  43.     if (group   != (AP_ptr *) 0)
  44.     *group   = (AP_ptr)   0;
  45.     if (name    != (AP_ptr *) 0)
  46.     *name    = (AP_ptr)   0;
  47.     if (local   != (AP_ptr *) 0)
  48.     *local   = (AP_ptr)   0;
  49.     if (domain  != (AP_ptr *) 0)
  50.     *domain  = (AP_ptr)   0;
  51.     if (route   != (AP_ptr *) 0)
  52.     *route   = (AP_ptr)   0;
  53.  
  54.     for (gotlocal = FALSE; ; tree = tree -> ap_chain) {
  55.                     /* print munged addr                  */
  56.     switch (tree -> ap_obtype) {
  57.         case APV_NIL: 
  58.         retptr = (AP_ptr) 0;
  59.         goto endit;
  60.  
  61.         case APV_CMNT:        /* Output value as comment */
  62.         break;
  63.  
  64.         case APV_NPER: 
  65.         perlev++;
  66.         if (name != (AP_ptr *) 0 && *name == (AP_ptr) 0)
  67.             *name = tree;
  68.         break;
  69.  
  70.         case APV_PRSN:
  71.         break;
  72.  
  73.         case APV_EPER: 
  74.         perlev--;
  75.         break;
  76.  
  77.         case APV_NGRP: 
  78.         grplev++;
  79.         if (group != (AP_ptr *) 0 && *group == (AP_ptr) 0)
  80.             *group = tree;
  81.         break;
  82.  
  83.         case APV_GRUP:
  84.         break;
  85.  
  86.         case APV_EGRP: 
  87.         grplev--;
  88.         break;
  89.  
  90.         case APV_WORD: 
  91.         case APV_MBOX: 
  92.         if (local != (AP_ptr *) 0 && *local == (AP_ptr) 0)
  93.             *local = tree;
  94.         gotlocal = TRUE;
  95.  
  96.         break;
  97.  
  98.         case APV_DLIT:
  99.         case APV_DOMN:
  100.         if (gotlocal) {         /* reference after local        */
  101.             if (domain != (AP_ptr *) 0 && *domain == (AP_ptr) 0)
  102.             *domain = tree;
  103.         } else {                /* must be 822 route    */
  104.                     /* domain precedes local-part   */
  105.             if (route != (AP_ptr *) 0 && *route == (AP_ptr) 0)
  106.             *route = tree;
  107.         }
  108.         break;
  109.  
  110.         default: 
  111.         break;
  112.     }
  113.  
  114.     switch (tree -> ap_ptrtype) {
  115.         case APP_NXT:
  116.         if (tree -> ap_chain -> ap_obtype != APV_NIL) {
  117.             retptr = (AP_ptr) tree -> ap_chain;
  118.             goto endit;
  119.         }
  120.                  /* else DROP ON THROUGH               */
  121.         case APP_NIL:
  122.         retptr = (AP_ptr) OK;
  123.         goto endit;        /* Courtesy of Steve Kille */
  124.     }
  125.     }
  126.  
  127. endit:
  128.     return (retptr);
  129. }
  130.